 package uk.co.mmscomputing.device.twain;
 
 import java.io.PrintStream;
 import java.util.Vector;
 import uk.co.mmscomputing.device.scanner.ScannerIOException;
 
 public class TwainSourceManager
   implements TwainConstants
 {
   private TwainSource source;
 
   TwainSourceManager(long paramLong)
   {
     this.source = new TwainSource(this, paramLong, false);
     this.source.getDefault();
   }
 
   int getConditionCode() throws TwainIOException {
     byte[] arrayOfByte = new byte[4];
     int i = jtwain.callSourceManager(1, 8, 1, arrayOfByte);
     if (i != 0) {
       throw new TwainResultException("Cannot retrieve twain source manager's status.", i);
     }
     return jtwain.getINT16(arrayOfByte, 0);
   }
 
   public void call(int paramInt1, int paramInt2, int paramInt3, byte[] paramArrayOfByte) throws TwainIOException {
     int i = jtwain.callSourceManager(paramInt1, paramInt2, paramInt3, paramArrayOfByte);
     switch (i) { case 0:
       return;
     case 1:
       throw new TwainFailureException(getConditionCode());
     case 2:
       throw new TwainResultException.CheckStatus();
     case 3:
       throw new TwainResultException.Cancel();
     case 4:
       return;
     case 5:
       throw new TwainResultException.NotDSEvent();
     case 6:
       throw new TwainResultException.TransferDone();
     case 7:
       throw new TwainResultException.EndOfList();
     }
 
     throw new TwainResultException("Failed to call source manager.", i);
   }
 
   TwainSource getSource() {
     return this.source;
   }
   TwainSource selectSource() throws TwainIOException {
     this.source.checkState(3);
     this.source.setBusy(true);
     try {
       this.source.userSelect();
       return this.source;
     } catch (TwainResultException.Cancel localCancel) {
       return this.source;
     }
     finally
     {
       this.source.setBusy(false);
     }
   }
 
   void getIdentities(Vector paramVector) throws ScannerIOException {
     this.source.checkState(3);
     this.source.setBusy(true);
     try {
       TwainIdentity localTwainIdentity = new TwainIdentity(this);
       localTwainIdentity.getFirst();
       paramVector.add(localTwainIdentity);
       while (true) {
         localTwainIdentity = new TwainIdentity(this);
         localTwainIdentity.getNext();
         paramVector.add(localTwainIdentity);
       }
     } catch (TwainResultException.EndOfList localEndOfList) {
     } catch (TwainIOException localTwainIOException) {
       System.out.println(getClass().getName() + ".getIdentities:\n\t" + localTwainIOException);
     } finally {
       this.source.setBusy(false);
     }
   }
 
   TwainSource selectSource(String paramString) throws ScannerIOException {
     this.source.checkState(3);
     this.source.setBusy(true);
     try {
       this.source.select(paramString);
       return this.source;
     } finally {
       this.source.setBusy(false);
     }
   }
 
   TwainSource openSource() throws TwainIOException {
     this.source.checkState(3);
     this.source.setBusy(true);
     try {
       this.source.open();
       if (!this.source.isDeviceOnline()) {
         this.source.close();
         throw new TwainIOException("Selected twain source is not online.");
       }
       this.source.setState(4);
       return this.source;
     } catch (TwainResultException.Cancel localCancel) {
       this.source.setBusy(false);
       return this.source;
     } catch (TwainIOException localTwainIOException) {
       this.source.setBusy(false);
       throw localTwainIOException;
     }
   }
 }

